* Table 8
use "temp/EIA_clean.dta", clear

preserve
	keep if exporter==1
	bys year: egen xip10 = pctile(xi*100), p(10)
	bys year: egen xip25 = pctile(xi*100), p(25)
	bys year: egen xip50 = pctile(xi*100), p(50)
	bys year: egen xip75 = pctile(xi*100), p(75)
	bys year: egen xip95 = pctile(xi*100), p(95)
	bys year: egen xiavg = mean(xi*100)	
	collapse xip10 xip25 xip50 xip75 xip95 xiavg, by(year)
	label var xip10 "10th pctile si"
	label var xip25 "25th pctile si"
	label var xip50 "50th pctile si"
	label var xip75 "75th pctile si"
	label var xip95 "95th pctile si"
	label var xiavg "xiavg"
	keep if year>=1994 & year<=1999	
	* compute change between 1994 and 95-99 average	
	gen temp1 = 0
	replace temp1=1 if year>1994	
	foreach x of var xip* xiavg {
	bys temp1: egen `x'avg = mean(`x')
	drop `x'
	}	
	drop temp1
	keep if year==1994 | year==1995
	foreach x of var xip*avg xiavgavg {
	gen `x'_d = `x' - `x'[_n-1]
	drop `x'
	}	
	keep if year==1995
	drop year
	label var xip10avg_d "10th pctile sx"
	label var xip25avg_d "25th pctile sx"
	label var xip50avg_d "50th pctile sx"
	label var xip75avg_d "75th pctile sx"
	label var xip95avg_d "95th pctile sx"
	label var xiavgavg_d "Mean"
	
	export excel "../../Output/TableA2_Data", first(varl) sh("Percentiles_and_Mean") replace
restore
bys year: egen Exports = total(exports)
bys year: gen xiAGG = Exports / totalsales
preserve
	collapse xiAGG, by (year)
	label var xiAGG "Export Share"
	* compute change between avg of 95-99 and 94
	keep if year>=1994 & year<=1999
	gen temp1 = 0
	replace temp1 = 1 if year==1994
	foreach x of var xiAGG{
	gen `x'temp = `x' * temp1
	egen `x'94 = total(`x'temp)
	gen `x'_delta = (`x'-`x'94)*100
	drop `x'temp
	}
	drop if year==1994
	collapse xiAGG_delta
	label var xiAGG_delta "Aggregate"
	export excel "../../Output/TableA2_Data", first(varl) sh("Aggregate") 
restore
